<template>
  <el-form :model="form" label-width="120px">
    <el-form-item label="客户名字">
      <el-input v-model="form.saleCname" />
    </el-form-item>
<!-- 	<el-form-item label="机会来源">
	  <el-input v-model="form.changeId" />
	</el-form-item> -->
	<el-form-item label="机会来源">
	      <el-select v-model="form.changeSource" placeholder="请选择机会来源">
	        <el-option label="促销" value="促销" />
	        <el-option label="广告" value="广告" />
			<el-option label="搜索引擎" value="搜索引擎" />
			<el-option label="线上咨询" value="线上咨询" />
			<el-option label="电话咨询" value="电话咨询" />
			<el-option label="邮件咨询" value="邮件咨询" />
			<el-option label="客户介绍" value="客户介绍" />
	      </el-select>
	</el-form-item>
	<el-form-item label="联系人">
	  <el-input v-model="form.saleContacts" />
	</el-form-item>
	<el-form-item label="联系电话">
	  <el-input v-model="form.salePhone" />
	</el-form-item>
<!-- 	<el-form-item label="成功几率">
	  <el-input v-model="form.saleSuccess" />
	</el-form-item> -->
	<el-form-item label="成功几率">
	      <el-select v-model="form.saleSuccess" placeholder="请选择成功几率">
	        <el-option label="20%" value="20%" />
			<el-option label="30%" value="30%" />
	        <el-option label="50%" value="50%" />
	        <el-option label="60%" value="60%" />
			<el-option label="70%" value="70%" />
			<el-option label="80%" value="80%" />
	      </el-select>
	</el-form-item>
	
	<el-form-item label="机会概要">
	  <el-input v-model="form.saleSynopsis" />
	</el-form-item>
	<el-form-item label="机会描述">
	  <el-input v-model="form.saleDesc" type="textarea" />
	</el-form-item>
	
    
    <el-form-item>
      <el-button type="primary" @click="onSubmit">提交</el-button>
      <el-button>重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script  setup>
import { reactive } from 'vue'
import axios from 'axios'
import qs from 'qs'
import {getCurrentInstance} from 'vue'
const {proxy} = getCurrentInstance()	

const form = reactive({
  salaCname: '',
  changeId: '',
  saleContacts: '',
  salePhone: '',
  saleSuccess: '',
  saleSynopsis: '',
  saleDesc: '',
})

const onSubmit = () => {
	//axios.post:发送异步请求
	//请求的参数需要把json对象，进行转换：qs。stringify（form）
	//then：请求结束，获取响应到的结果，然后再函数内部处理增数据。
  form.token = proxy.$token.value
  axios.post("http://localhost:8080/saleChance/add",qs.stringify(form)).then(res => {
	  // console.log(res.date.msg)
	  console.log(res.data.msg)
	  if(res.data.msg == 'success'){
	  	window.location.href="http://localhost:8066/#/sc/list";   
	  }else{
		  alert("错误！")
	  }
  })
}
</script>
